/**
 *Copyright(c) HNA SYSTEMS Co., LTD
 *
 *@date 2013-7-18
 * 	
 *Original Author: 郑兴(zhengxing)
 *
 *ChangeLog
 *
 */
package com.hnas.sys.orm;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.hnas.core.util.StringUtil;
import com.hnas.sys.domain.ResourceStatus;
import com.hnas.sys.domain.ResourceType;

/**
 * @author 郑兴(zhengxing)
 *
 */
@Entity
@Table(name="sys_resource")
public class Resource {
    @Id @GeneratedValue(strategy=IDENTITY)    
    @Column(name="id",  nullable=false)
	private long id;
	private String name;
	@Column(name="resource_url",unique=true)
	private String resource;
	private int priority;
	private String description;
	@Column(name="type_str")
	private String typeStr;
	@Transient
	private ResourceType type;
	@Column(name="status", length=5)
	private String statusStr;
	@Transient
	private ResourceStatus status;
	@Column(name="PACKAGE_ID")
	private Long menuPackageID;
	@Column(name="operate_Type",columnDefinition="int default 0")
	private int operateType=0;//操作类型：1增/2删/3改/4查/5导入/6导出
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="resource")
	private Set<AuthorityResource> authorityResources = new HashSet<AuthorityResource>();
	/**
	 * @return the id
	 */
//	@Id
//	@GeneratedValue
	public long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the resource
	 */
	public String getResource() {
		return resource;
	}
	/**
	 * @param resource the resource to set
	 */
	public void setResource(String resource) {
		this.resource = resource;
	}
	/**
	 * @return the typeStr
	 */
	
	public String getTypeStr() {
		return typeStr;
	}
	/**
	 * @param typeStr the typeStr to set
	 */
	public void setTypeStr(String typeStr) {
		this.typeStr = typeStr;
		if(StringUtil.isNotEmpty(typeStr)) {
			this.type = ResourceType.valueOfAlias(typeStr);
		} else {
			this.type = null;
		}
	}
	/**
	 * @return the type
	 */
//	@Transient
	public ResourceType getType() {
		if(!StringUtil.isEmpty(typeStr)) {
			return ResourceType.valueOfAlias(typeStr);
		}
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(ResourceType type) {
		this.type = type;
		if(null != type) {
			this.typeStr = type.getAlias();
		} else {
			this.typeStr = null;
		}
	}
	/**
	 * @return the priority
	 */
	public int getPriority() {
		return priority;
	}
	/**
	 * @param priority the priority to set
	 */
	public void setPriority(int priority) {
		this.priority = priority;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the statusStr
	 */
	
	public String getStatusStr() {
		return statusStr;
	}
	/**
	 * @param statusStr the statusStr to set
	 */
	public void setStatusStr(String statusStr) {
		this.statusStr = statusStr;
		if(StringUtil.isNotEmpty(statusStr)) {
			this.status = ResourceStatus.valueOfAlias(statusStr);
		} else {
			this.status = null;
		}
	}
	/**
	 * @return the status
	 */
//	@Transient
	public ResourceStatus getStatus() {
		if(!StringUtil.isEmpty(statusStr)) {
			return ResourceStatus.valueOfAlias(statusStr);
		}
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(ResourceStatus status) {
		this.status = status;
		if(null != status) {
			this.statusStr = status.getAlias();
		} else {
			this.statusStr = null;
		}
	}
	/**
	 * @return the menuPackageID
	 */
	
	public Long getMenuPackageID() {
		return menuPackageID;
	}
	/**
	 * @param menuPackageID the menuPackageID to set
	 */
	public void setMenuPackageID(Long menuPackageID) {
		this.menuPackageID = menuPackageID;
	}
	/**
	 * @return the authorityResources
	 */
	
	public Set<AuthorityResource> getAuthorityResources() {
		return authorityResources;
	}
	/**
	 * @param authorityResources the authorityResources to set
	 */
	public void setAuthorityResources(Set<AuthorityResource> authorityResources) {
		this.authorityResources = authorityResources;
	}
	public int getOperateType() {
		return operateType;
	}
	public void setOperateType(int operateType) {
		this.operateType = operateType;
	}
}
